function clearDeadline()
{
    document.forms[0]['deadlineYear'].selectedIndex = 0;
    document.forms[0]['deadlineMonth'].selectedIndex = 0;
    document.forms[0]['deadlineDay'].selectedIndex = 0;
}

function selectDate(controlPrefix, dateStr, hasEmptyOption)
{
    var frm = document.forms[0];
    var date = strToDate(dateStr);

    var yearFld = frm[controlPrefix + 'Year'];
    var startIndex = hasEmptyOption ? 1 : 0;
    var yearIndex = hasEmptyOption + date.getFullYear() - yearFld.options[startIndex].value;

    // ignore non existent year
    if (yearIndex < startIndex || yearIndex >= yearFld.options.length) return;

    yearFld.options[yearIndex].selected = true;
    frm[controlPrefix + 'Month'].options[date.getMonth() + 1].selected = true;
    frm[controlPrefix + 'Day'].options[date.getDate()].selected = true;
}

function selectDeadline(dateStr)
{
    selectDate('deadline', dateStr, true);
}

function getDeadline()
{
    var frm = document.forms[0];

    var year    = frm['deadlineYear'].options[frm['deadlineYear'].selectedIndex].value;
    var month   = frm['deadlineMonth'].options[frm['deadlineMonth'].selectedIndex].value;
    var day     = frm['deadlineDay'].options[frm['deadlineDay'].selectedIndex].value;

    if (year == 0 || month == 0 || day ==0)
        return "";

    return  year + '-' + month + '-' + day;
}

function selectCompletionDate(dateStr)
{
    selectDate('completionDate', dateStr, false);
}

function getCompletionDate()
{
    var frm = document.forms[0];

    var year    = frm['completionDateYear'].options[frm['completionDateYear'].selectedIndex].value;
    var month   = frm['completionDateMonth'].options[frm['completionDateMonth'].selectedIndex].value;
    var day     = frm['completionDateDay'].options[frm['completionDateDay'].selectedIndex].value;

    return  year + '-' + month + '-' + day;
}
